#!/bin/bash
LOCK="/tmp/pcp.lock"
if [ -f "$LOCK" ];
then
	CMD="$0"
	ps -ef|grep "${CMD}" > /dev/null 2>&1
	if [ $? -ne 0 ];
	then
 		exit 0 
	else
		rm -f "$LOCK" 
		CMD="./pcp -d"
	fi
fi

for ((;;));
do
	touch $LOCK
	ANS=`ps -ef|grep "${CMD}"|grep -v grep 2>&1`
	if [ ${#ANS} -eq 0 ];
	then
		echo "沒找到"
		cd /home/anton/Community/pcp/talk/examples/pcp
		$CMD > /tmp/pcp.log 2> /tmp/pcp.err
		date
		echo "挫塞..."
	else
		echo "找到"
	fi
	sleep 10s
done
